// Author: Bjorn Schobben

#include "Scalar.h"
#include <math.h>
#include <stdio.h>

const Scalar Scalar::PI = 3.1415926535897932384626433832795;

Scalar::Scalar(double s): scalar(s)
{
}

Scalar::Scalar(const Scalar& rhs): scalar(rhs.scalar)
{
}

Scalar::~Scalar()
{
}

int Scalar::GetInt() const
{
	return (int)scalar;
}

int Scalar::GetRoundInt() const
{
	return (int)(scalar + 0.5);
}

Scalar Scalar::operator-() const
{
	return -scalar;
}

Scalar& Scalar::operator+=(const Scalar& rhs)
{
	scalar += rhs.scalar;

	return *this;
}

Scalar Scalar::operator+(const Scalar& rhs) const
{
	Scalar result = *this;
	result += rhs;
	return result;
}


Scalar& Scalar::operator-=(const Scalar& rhs)
{
	scalar -= rhs.scalar;

	return *this;
}

Scalar Scalar::operator-(const Scalar& rhs) const
{
	Scalar result = *this;
	result -= rhs;
	return result;
}

Scalar& Scalar::operator*=(const Scalar& rhs)
{
	scalar *= rhs.scalar;

	return *this;
}

Scalar Scalar::operator*(const Scalar& rhs) const
{
	Scalar result = *this;
	result *= rhs;
	return result;
}

Scalar& Scalar::operator/=(const Scalar& rhs)
{
	scalar /= rhs.scalar;

	return *this;
}

Scalar Scalar::operator/(const Scalar& rhs) const
{
	Scalar result = *this;
	result /= rhs;
	return result;
}

Scalar& Scalar::operator=(const Scalar &rhs)
{
	scalar = rhs.scalar;
	return *this;
}

bool Scalar::operator<(const Scalar& rhs) const
{
	return scalar < rhs.scalar;
}

bool Scalar::operator>(const Scalar& rhs) const
{
	return scalar > rhs.scalar;
}

Scalar Scalar::CosineDegree() const
{
	// 180 degrees = PI radian
	// 1 degree = PI/180 radian

	Scalar radian = (*this) * PI / 180;

	return radian.Cosine();
}

Scalar Scalar::SineDegree() const
{
	// 180 degrees = PI radian
	// 1 degree = PI/180 radian

	Scalar radian = (*this) * PI / 180;

	return radian.Sine();
}


Scalar Scalar::Cosine() const
{
	return cos(scalar);
}

Scalar Scalar::Sine() const
{
	return sin(scalar);
}

Scalar Scalar::Sqrt() const
{
	return sqrt(scalar);
}

Scalar Scalar::Abs() const
{
	if (scalar > 0)
		return scalar;
	else
		return -scalar;
}

bool Scalar::IsNegative() const
{
	return scalar<0;
}


double Scalar::GetValue() const
{
	return scalar;
}

void Scalar::ConvertToInteger()
{
	scalar = (double)((int)scalar);
}
